
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <conf.h>

#include "setting.h"

struct setting_t g_setting;

void setting_init()
{
	bzero(&g_setting, sizeof(g_setting));

	// init default value

	return;
}

int setting_load(char *file)
{
	if(conf_load(file) == -1) {
		return -1;
	}

	if(conf_number("daemon") != -9999) {
		g_setting.daemon = conf_number("daemon");
	}
	if(conf_number("port") != -9999) {
		g_setting.port = conf_number("port");
	} else {
		return -1;
	}

	if(conf_string("exec") != NULL) {
		strncpy(g_setting.exec, conf_string("exec"), MAX_STRLEN);
	} else {
		return -1;
	}

	if(conf_string("args") != NULL) {
		strncpy(g_setting.args, conf_string("args"), MAX_STRLEN);
	} 

	conf_destroy();

	return 0;
}


